<html>
    <head>
        <title>Test</title>
        <style>

          form {
            flow:row(input textarea, button, output);
            border-spacing:0.5em;
            size:*;
          }

          form > input,
          form > textarea,
          form > output { width:*; }

          div#received {
            size:*;
            border:1dip solid;
          }

        </style>
        <script type="text/tiscript">

          var socket = null;

          function self.ready() {
          }

          function acceptor(socket) {

            $(output#listening-status).value = "connected";
            $(button#listen).state.disabled = true;
            $(input#name).state.disabled = true;
            $(textarea#to-send).state.disabled = false;
            $(button#send).state.disabled = false;

            socket << event send {
              $(output#sending-status).value = "data sent";
            }

            socket << event data (message) {
              $(div#received).$append(<div>{message}</div>);
            }

            socket << event error(error) {
              $(div#received).value = "error:" + error;
            }

            socket << event close {
              $(output#listening-status).value = "disconnected";
              $(button#listen).state.disabled = false;
              $(input#name).state.disabled = false;
              $(textarea#to-send).state.disabled = true;
              $(button#send).state.disabled = true;
            }

            $(button#send) << event click  {
              var data = $(textarea#to-send).value;
              socket.send(data);
            }

            return true; // we accept this connection
          }

          event click $(button#listen) 
          {
            var pipeName = $(input#name).value;
            if( !pipeName ) {
              $(input#name).state.focus = true;
              return;
            }

            $(output#listening-status).value = "listening";

            Net.Socket.listen(acceptor,pipeName);
           
          }

        </script>
    </head>
    <body>

      <h1>Server</h1>

      <h2>Pipe / local sockets communication demo</h2>

      <form>
       <input|text #name novalue="pipe name" /> <button#listen >Start</button> <output|text #listening-status />
       <textarea #to-send novalue="data to send" disabled/> <button #send disabled>Send</button> <output|text #sending-status />
       <div #received></div> 
      </form>
    </body>
</html>